package com.example.bigeventMaven.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by 10446 on 2017/9/8.
 */
@Service
public class JDBCService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public List getList(){
        String sql = "select * from test";

        return (List<JDBCManager>) jdbcTemplate.query(sql, new RowMapper() {
            @Override
            public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                JDBCManager obj = new JDBCManager();
                obj.setId(resultSet.getInt("id"));
//                System.out.println(resultSet.getInt("id"));
                return obj;
            }

        });
    }
}
